/**
 * AluiCommons -  http://code.google.com/p/alui-toolbox/
 * Copyright (c) 2008-2009
 * by Fabien Sanglier
 * 
 * This file is part of AluiCommons.
 * 
 * AluiCommons is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * AluiCommons is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AluiCommons.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Data;
using System.Configuration;
using System.Text;
using com.plumtree.server;

namespace AluiServerLib.Helper
{
    public class WebHelper
    {
        public static string CreateTreePickerTag(int classid, string linktext, string title, string subtitle, string jsfunctionname)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<pt:standard.treeLink xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'");
            sb.Append(" pt:RootID='1' pt:Multi='true' pt:CommunityMode='3' pt:SelectMd='2' pt:Access='15' pt:Class='" + classid + "' pt:SubmitMd='2'");
            sb.Append(" pt:Submit='" + jsfunctionname + "' pt:Title='" + title + "' pt:SubTitle='" + subtitle + "'");
            sb.Append(" pt:windowName='myWindow' pt:windowFeatures='location=no,menubar=no,height=500,width=300'");
            sb.Append(">");
            sb.Append(linktext);
            sb.Append("</pt:standard.treeLink>");

            return sb.ToString();
        }

        public static string CreateTreePickerJS(string jsfunctionname, string targetInputElemId, string valueseparator)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("function " + jsfunctionname + "(arrIn){");
            sb.AppendLine("\t" + "var iLength;");
            sb.AppendLine("\t" + "var itemNames = \"\";");
            sb.AppendLine("\t" + "var itemObjectIDs = \"\";");
            sb.AppendLine("\t" + "iLength = arrIn.length;");
            sb.AppendLine("\t" + "for (var i=0; i < iLength; i++)");
            sb.AppendLine("\t" + "{");
            sb.AppendLine("\t\t" + "if(itemNames != \"\")");
            sb.AppendLine("\t\t\t" + "itemNames += \"" + valueseparator + "\";");
            sb.AppendLine("\t\t" + "itemNames += arrIn[i].Name;");
            sb.AppendLine("\t\t" + "if(itemObjectIDs != \"\")");
            sb.AppendLine("\t\t\t" + "itemObjectIDs += \"" + valueseparator + "\";");
            sb.AppendLine("\t\t" + "itemObjectIDs += arrIn[i].ObjectID;");
            sb.AppendLine("\t" + "}");
            sb.AppendLine("\t" + "document.getElementById('" + targetInputElemId + "').value = itemObjectIDs;");
            sb.AppendLine("}");
            return sb.ToString();
        }
    }
}
